﻿using System.Drawing;
using System.Globalization;
using System.Web;

namespace WebImageResizer.Filters
{
	internal class RotateFilter : IImageFilter
	{
		#region IImageFilter Members

		public bool Process(HttpContext context, ref Bitmap bitmap)
		{
			string rotateParameter = context.Request["rotate"];
			if (string.IsNullOrEmpty(rotateParameter))
			{
				return false;
			}

			float angle;
			if (float.TryParse(rotateParameter, NumberStyles.Float, CultureInfo.InvariantCulture, out angle))
			{
				IImageTool imageTool = Factory.GetImageTool();
				bitmap = imageTool.Rotate(bitmap, angle);
				return true;
			}

			return false;
		}

		#endregion
	}
}